package com.killgun;

import com.jme3.app.DebugKeysAppState;
import com.jme3.app.FlyCamAppState;
import com.jme3.app.SimpleApplication;
import com.jme3.app.StatsAppState;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.killgun.configuration.ConfigManager;
import com.killgun.level.LevelLoader;
import com.killgun.mainplayer.MainPlayerAppState;
import com.killgun.physics.PhysicsAppState;
import java.util.Properties;

/**
 * @author Tim Terhorst, Dillon Wesley, Chris Woodward, Austin Allman
 */
public class MainApp extends SimpleApplication {

    public static final String GAME_TITLE = "Killgun";
    private AppSettings gameSettings;
    private Properties properties = ConfigManager.getInstance();

    public MainApp() {
        /*
         * This starts up the initial app states that get the game going
         * instead of main player and physics we will want the stuff for adding 
         * the start intro screens and loading the main menu
         */
        super(new StatsAppState(), new FlyCamAppState(), new DebugKeysAppState(),
                new PhysicsAppState(), new MainPlayerAppState());
        gameSettings = new AppSettings(true);
        gameSettings.setTitle(MainApp.GAME_TITLE);
    }

    public static void main(String[] args) {
        MainApp app = new MainApp();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        //Screen goes black for some reason, lost many hours of sleep over it ><
        // stateManager.attach(new LevelAppState());

        //Level load code that was in level app state but didnt work
        //comment the following block to test out the levelappstate
        LevelLoader levelLoader = new LevelLoader(assetManager);
        Spatial currentLevel = levelLoader.loadLevel(properties.getProperty("lvl.one"));
        getRootNode().attachChild(currentLevel);
        getStateManager().getState(PhysicsAppState.class).addSolid(currentLevel);
        //comment to here

        //Blue box of death
        Box b = new Box(Vector3f.ZERO, 1, 1, 1);
        Geometry geom = new Geometry("Box", b);

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);
        geom.setMaterial(mat);

        rootNode.attachChild(geom);
    }

    @Override
    public void simpleUpdate(float tpf) {
    }

    /**
     * @return the gameSettings
     */
    public AppSettings getGameSettings() {
        return gameSettings;
    }

    /**
     * @param aGameSettings the gameSettings to set
     */
    public void setGameSettings(AppSettings aGameSettings) {
        gameSettings = aGameSettings;
    }
}
